package com.wisemoresystem.seal.action.config.macconfig;

import java.util.List;
import java.util.Map;

import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_mac_config;
import com.wisemoresystem.seal.service.MacConfigService;
import com.wisemoresystem.seal.service.MacService;
import com.wisemoresystem.seal.service.PaperService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 印控仪配置
 * 
 * @author Administrator
 *
 */
@Controller("macconifg")
@Scope("prototype")
@RequestMapping("/ix/config/mac")
public class MacConfigAction extends ProjBaseAction {
	@Autowired
	private MacConfigService macconfigservic;
	@Autowired
	private MacService macservice;

	@Autowired
	private PaperService paperservice;

	/**
	 * 印控仪配置列表
	 * 
	 * @param mac_id
	 *            印控仪id
	 * @param type
	 *            类型
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list(String mac_id, String type) {

		t_mac_config macConfig = macconfigservic.selectMacConfig(type);
		List<Map<String, Object>> macList = macservice.selectMac(WebTools
				.getCurrentBankId());
		List<Map<String, Object>> paperList = paperservice.selectPaper();

		ModelAndView mv = new ModelAndView("jsp/config/mac/list");
		mv.addObject("macList", macList);
		mv.addObject("macConfig", macConfig);
		mv.addObject("type", type);
		mv.addObject("paperList", paperList);
		return mv;
	}

	/**
	 * 印控仪配置添加
	 * 
	 * @param macconfig
	 *            印控仪配置
	 * @param type
	 *            类型
	 * @param macconfig_id
	 *            配置id
	 * @return
	 */
	@RequestMapping("/add")
	private ModelAndView add(t_mac_config macconfig, String type,
			String macconfig_id) {
		if (ChkTools.isNull(macconfig_id)) {

			macconfig.setMac_id(type);
			oc.saveObj(macconfig);
			super.setTipMsg("添加成功", Tip.Type.success);
			logT.logH("添加印控配置", t_mac_config.class, macconfig.get_id());

		} else {

			t_mac_config macConfigDb = oc.findObjById(macconfig_id,
					t_mac_config.class);

			macConfigDb.setMac_id(type);
			macConfigDb.setPage_height(macconfig.getPage_height());
			macConfigDb.setPage_width(macconfig.getPage_width());
			macConfigDb.setSound_print_res(macconfig.getSound_print_res());
			macConfigDb.setSound_print_start(macconfig.getSound_print_start());
			macConfigDb.setTime_apart(macconfig.getTime_apart());
			macConfigDb
					.setTime_detail_height(macconfig.getTime_detail_height());
			macConfigDb.setTime_detail_width(macconfig.getTime_detail_width());
			macConfigDb.setTime_first_stop_(macconfig.getTime_first_stop_());
			macConfigDb.setWork_type(macconfig.getWork_type());
			macConfigDb.setUser_height(macconfig.getUser_height());
			macConfigDb.setUser_width(macconfig.getUser_width());
			macConfigDb.setUser_id(macconfig.getUser_id());
			macConfigDb.setSeal_height(macconfig.getSeal_height());
			macConfigDb.setSeal_width(macconfig.getSeal_width());
			macConfigDb.setSeal_stop_time(macconfig.getSeal_stop_time());
			macConfigDb.setPaper_id(macconfig.getPaper_id());

			oc.updateObj(macConfigDb);
			super.setTipMsg("修改成功", Tip.Type.success);
			logT.logH("修改印控配置", t_mac_config.class, macConfigDb.get_id());
		}

		ModelAndView mv = new ModelAndView("redirect:list.htm?type=" + type);
		return mv;
	}
}
